#include <iostream>
#include <unordered_map>
#include <gtest/gtest.h>

/*****************************************************************************
 * 独立测试套件: 
 *     在每次的单元测试中, 都会重新初始化测试环境, 完毕后清理环境
 *     测试环境类中, 可以定义成员变量, 成员变量是独立, 与当前测试套件相关的单元测试才能访问的
 *     测试的命名必须与套件环境类名一致
 */

class MyTest : public testing::Test
{
public:
    static void SetUpTestCase()
    {
        std::cout << "Initialize the total environment before all unit tests\n";
    }
    static void TearDownTestCase()
    {
        std::cout << "Clean up the total environment before all unit tests\n";
    }

    virtual void SetUp()
    {
        std::cout << "Stand-alone unit test initialization\n";
        hashmap_.emplace("eat", "吃");
        hashmap_.emplace("dinner", "晚饭");
    }
    virtual void TearDown()
    {
        std::cout << "Standalone unit test cleanup\n";
        hashmap_.clear();
    }
public:
    std::unordered_map<std::string, std::string> hashmap_;
};

TEST_F(MyTest, insert_test1)
{
    hashmap_.emplace("monring", "早上");
    EXPECT_EQ(hashmap_.size(), 3);
}

TEST_F(MyTest, insert_test2)
{
    hashmap_.emplace("monring", "早上");
    hashmap_.emplace("afternoon", "下午");
    EXPECT_EQ(hashmap_.size(), 3);
}

int main(int argc, char *argv[])
{
    testing::InitGoogleTest(&argc, argv);
    RUN_ALL_TESTS();
    return 0;
}